package com.sky.bo;

import com.sky.dto.EmployeeAddDto;
import com.sky.dto.EmployeeEditDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.LocalDateTime;


/**
 * 修改员工bo
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("修改员工入参")
public class EmployeeEditBo implements Serializable {

    @ApiModelProperty("员工id")
    @NotNull(message = "id不能为空")
    private Long id;

    @ApiModelProperty("身份证")
    @NotBlank(message = "身份证不能为空！")
    @Pattern(message = "身份证不合法！",regexp = "^[1-9]\\d{5}(18|19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[\\dXx]$")
    private String idNumber;

    @ApiModelProperty("姓名")
    @NotBlank(message = "姓名不能为空！")
    @Size(max = 30,message = "姓名不能超过30个字符")
    private String name;

    @ApiModelProperty("手机号")
    @NotBlank(message = "手机号不能为空！")
    @Pattern(message = "手机号不合法！",regexp = "^1[3-9]\\d{9}$")
    private String phone;

    @ApiModelProperty("性别")
    @NotBlank(message = "性别不能为空！")
    @Size(max = 1,message = "性别不能超过1个字符")
    private String sex;

    @ApiModelProperty("账号")
    @NotBlank(message = "账号不能为空！")
    @Size(max = 30,message = "账号不能超过30个字符")
    private String username;

    //DTO转换
    public EmployeeEditDto getDto() {
        EmployeeEditDto dto = new EmployeeEditDto();
        dto.setId(id);
        dto.setIdNumber(idNumber);
        dto.setName(name);
        dto.setPhone(phone);
        dto.setUsername(username);
        dto.setSex(sex);
        LocalDateTime date = LocalDateTime.now();
        dto.setUpdateTime(date);
        return dto;
    }
}
